package com.openscorer;

import java.util.ArrayList;
import java.util.Iterator;

public class Repeated extends Scorable {
	public Repeated(Scorable prototype) {
		prototype_ = prototype;
		list_ = new ArrayList<Scorable>();
	}
	public Scorable round(int i) { return list_.get(i); }
	public int num_rounds() { return list_.size(); }
	
	// The following are for internal use only.
	public FormattingOptions getFOptions() {
		return prototype_.getFOptions();
	}
	public Scorable add() {
		list_.add(prototype_.deepCopy());
		return list_.get(list_.size() - 1);
	}
	public String getName() { return prototype_.getName(); }
	public ArrayList<Scorable> value() { return list_; }

	public void visit(ScorableVisitor v) {
		v.visitRepeated(this);
		for (Iterator<Scorable> it = list_.iterator(); it.hasNext();) {
			v.visit(it.next());
		}
		v.endRepeated(this);
	}
	public Repeated deepCopy() {
		Repeated returnable = new Repeated(prototype_);
		for (Iterator<Scorable> it = list_.iterator(); it.hasNext();) {
			returnable.list_.add(it.next().deepCopy());
		}
		return returnable;
	}
	ArrayList<Scorable> list_;
	Scorable prototype_;
}
